package com.example.repository;

import com.example.entity.Comment;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

public interface CommentRepository {
    //一对多子查询
    @Results(id = "commentMap",value = {
            @Result(property = "id",column = "id",jdbcType = JdbcType.INTEGER,id = true),
            @Result(property = "articleId",column = "article_id",jdbcType = JdbcType.INTEGER),
            @Result(property = "content", column = "content",jdbcType = JdbcType.VARCHAR),
            @Result(property = "author", column = "author",jdbcType = JdbcType.VARCHAR)
    })
    @Select("select id,article_id,content,author from comment where article_id=#{id}")
    public List<Comment> findByArticleId(int id);

    //多对一
    @Results(id = "comment",value = {
            @Result(property = "id",column = "id",jdbcType = JdbcType.INTEGER,id = true),
            @Result(property = "articleId",column = "article_id",jdbcType = JdbcType.INTEGER),
            @Result(property = "content", column = "content",jdbcType = JdbcType.VARCHAR),
            @Result(property = "author", column = "author",jdbcType = JdbcType.VARCHAR),
            @Result(property = "article", column = "article_id",one = @One(select = "com.example.repository.ArticleRepository.findArticleById"))
    })
    @Select("select * from comment")
    public List<Comment> findArticleByComment();


}
